package com.samphanie.auiu.biz_detail.biz.notice

import android.content.Intent
import android.net.Uri
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.samphanie.auiu.biz_detail.R
import com.samphanie.auiu.common.utils.DateUtil
import com.samphanie.auiu.library.utils.AuiuRes
import com.samphanie.auiu.pub_mod.model.Notice
import com.samphanie.auiu.ui.item.AuiuDataItem
import com.samphanie.auiu.ui.item.AuiuViewHolder

/**
 * @author ZSY
 */
internal class NoticeItem(val data: Notice): AuiuDataItem<Notice, AuiuViewHolder>(data) {

    override fun onBindData(holder: AuiuViewHolder, position: Int) {
        mData?.apply {
            holder.findViewById<TextView>(R.id.tv_title)!!.text = title
            holder.findViewById<TextView>(R.id.icon)!!.text = AuiuRes.getString(R.string.if_notice_msg)
            holder.findViewById<TextView>(R.id.tv_sub_title)!!.text = subTitle
            holder.findViewById<TextView>(R.id.tv_publish_date)!!.text = DateUtil.getMDDate(createTime)
            holder.itemView.setOnClickListener {
                val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
                ContextCompat.startActivity(holder.itemView.context, intent, null)
            }
        }
    }

    override fun getItemLayoutRes(): Int {
        return R.layout.layout_notice_item
    }

}